<?php
/**
 * Description of Theme
 *
 * @author pdelavega
 */

class App_View_Helper_Theme
{

    /**
     * Returns site base url based on the current theme
     *
     *
     * @return string
     */
    public function theme($content = '', $prependBase = true,$site=null)
    {

        if ($prependBase) {
            $baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
        } else {
            $baseUrl = '';
        }

        //change this to match how you store your sessions
        $session = new Zend_Session_Namespace('Default');

        
        if ($site!=null)
        {
            $url = "/".$site."_theme".$content;
        }
        else
        {
            $url = '/' . $session->theme . $content;
        }
        
        $location = $_SERVER["DOCUMENT_ROOT"] . $url;
        
        if (file_exists($location))
        {
            return $baseUrl . $url;
        } else {
            // If theme doesn't exist then use the default theme
            $url = '/default' . $content;
            return $baseUrl . $url;
        }
    }
    
    public function themeAdmin($content = '', $prependBase = true)
    {

        if ($prependBase) {
            $baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
        } else {
            $baseUrl = '';
        }
        
        $url = '/' . $session->theme . '/admin';
        print $url;
        die();
        if (!file_exists($url))
        {
            symlink($url,APPLICATION_PATH.'/modules/admin/theme',1);
        }
        
        //change this to match how you store your sessions
        $session = new Zend_Session_Namespace('Default');

        $url .= '/'.$content;

        $location = DOCUMENT_ROOT . $url;

        if (file_exists($location))
        {
            return $baseUrl . $url;
        } else {
            // If theme doesn't exist then use the default theme
            $url = '/default' . $content;
            return $baseUrl . $url;
        }
    }

}

